home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Mail / EnhanceMail.1.3 / Source / MailReader.m < prev    next >
Encoding:
Text File  |  1996-04-06  |  5.2 KB  |  197 lines

  1. /* -*-C-*-
  2. *******************************************************************************
  3. *
  4. * File:         MailReader.m
  5. * RCS:          $Header: /usr/local/lib/cvs/EnhanceMail/MailReader.m,v 1.1.1.16 1996/04/07 00:20:21 cedman Exp $
  6. * Description:  
  7. * Author:       Carl Edman
  8. * Created:      Fri Oct 13 11:48:05 1995
  9. * Modified:     Sat Apr  6 19:17:24 1996 (Carl Edman) cedman@capitalist.princeton.edu
  10. * Language:     C
  11. * Package:      N/A
  12. * Status:       Experimental (Do Not Distribute)
  13. *
  14. * (C) Copyright 1995, but otherwise this file is perfect freeware.
  15. *
  16. *******************************************************************************
  17. */
  18.  
  19. #import "EnhanceMail.h"
  20. #import "MailReader.h"
  21. #import "MailBox.h"
  22. #import "XFace.h"
  23. #import "XImageURL.h"
  24. #import "Preferences.h"
  25.  
  26. #define MENU_MESSAGE_FLAG NXLocalizedStringFromTableInBundle("Localizable", EnhanceBundle, "Message/Flag", NULL, Slashed menu path to flag command)
  27. #define MENU_MESSAGE_STRIP NXLocalizedStringFromTableInBundle("Localizable", EnhanceBundle, "Message/Strip", NULL, Slashed menu path to strip command)
  28. #define MENU_MAILBOX_INDEX NXLocalizedStringFromTableInBundle("Localizable", EnhanceBundle, "Mailbox/Index", NULL, Slashed menu path to create index command)
  29. #define MENU_MAILBOX_UNINDEX NXLocalizedStringFromTableInBundle("Localizable", EnhanceBundle, "Mailbox/Delete index", NULL, Slashed menu path to remove index command)
  30.  
  31. static id index_menucell=nil;
  32. static id indextag_image=nil;
  33.  
  34. @implementation EnhanceMailReader
  35. + finishLoading:(struct mach_header *)header
  36.    {
  37.    char path[MAXPATHLEN+1];
  38.    
  39.    if (EnhanceBundle==0) EnhanceBundle=[NXBundle bundleForClass:[self class]];
  40.    [self poseAs:[self superclass]];
  41.    [[NXApp mainMenu] addSlashItem:MENU_MESSAGE_FLAG action:@selector(toggleFlagged:) keyEquivalent:0];
  42. #if 0
  43.    [[NXApp mainMenu] addSlashItem:MENU_MESSAGE_STRIP action:@selector(strip:) keyEquivalent:0];
  44. #endif
  45.    index_menucell=[[NXApp mainMenu] addSlashItem:MENU_MAILBOX_INDEX action:@selector(toggleIndexing:) keyEquivalent:0];
  46.  
  47.    if ([EnhanceBundle getPath:path forResource:"indexTag" ofType:"tiff"])
  48.       indextag_image=[[NXImage alloc] initFromFile:path];
  49.    
  50.    return self;
  51.    }
  52.  
  53. - loadMessage:(int)fp16 newMsg:(BOOL)fp20 withAllHeaders:(BOOL)fp24
  54.    {
  55.    const char *header;
  56.    id ret=[super loadMessage:fp16 newMsg:fp20 withAllHeaders:fp24];
  57.    if (EnhanceShowXImageURL
  58.        && (header=[mailMessage headerValueForKey:"X-Image-URL"]))
  59.       [command setXImageURL:header];
  60.    if (EnhanceShowXFace
  61.        && (header=[mailMessage headerValueForKey:"X-Face"]))
  62.       [command setXFace:header];
  63.    return ret;
  64.    }
  65.  
  66. - free
  67.    {
  68.    if (EnhanceAutoCompact && mailbox)
  69.       {
  70.       struct mboxstatus stat;
  71.       [mailbox getMailboxStatus:&stat];
  72.       if ((stat.delmsgno>0) && (![mailbox hasStore])) [self compact:self];
  73.       }
  74.    
  75.    return [super free];
  76.    }
  77.  
  78. - compact:sender
  79.    {
  80.    if (mailbox && [mailbox hasStore])
  81.       [self toggleIndexing:sender];
  82.    return [super compact:sender];
  83.    }
  84.  
  85. - strip:sender
  86.    {
  87. #if 0
  88.    id list=[matrix getSelectedCells:nil];
  89.    id cell;
  90.    int i;
  91.  
  92.    for(i=0;i<[list count];i++)
  93.       {
  94.       cell=[list objectAt:i];
  95.       if (cell==nil) continue;
  96.       /* XXX Strip every message of all NeXT/MIME/uuencoded attachments XXX */
  97.       }
  98.    
  99.    list=[list free];
  100. #endif
  101.    return self;
  102.    }
  103.  
  104. - (void)setFlagged:(BOOL)flag
  105.    {
  106.    id cell=[matrix selectedCell];
  107.    if (cell==nil) return;
  108.    [cell setFlagged:YES];
  109.    if (mailbox==nil) return;
  110.    [mailbox setState:'+' forMsg:[cell msgId] flush:NO];
  111.    [self display];
  112.    return;
  113.    }
  114.  
  115. - toggleIndexing:sender
  116.    {
  117.    if (mailbox==nil) return nil;
  118.    if ([mailbox hasStore])
  119.       [mailbox deleteStore];
  120.    else
  121.       [mailbox createStore];
  122.  
  123.    [self display];
  124.    [self windowDidBecomeMain:self];
  125.    [self updateStatus];
  126.    return self;
  127.    }
  128.  
  129. - windowDidBecomeMain:sender
  130.    {
  131.    const char *c;
  132.  
  133.    if ((mailbox==nil)||(index_menucell==nil)) return self;
  134.    
  135.    c=[mailbox hasStore] ? MENU_MAILBOX_UNINDEX : MENU_MAILBOX_INDEX;
  136.    if (c=rindex(c,'/')) [index_menucell setTitle:(c+1)];
  137.    return self;
  138.    }
  139.  
  140. - (void)updateStatus
  141.    {
  142.    const char *val;
  143.    char buf[MAXPATHLEN+1];
  144.    float size;
  145.    
  146.    [super updateStatus];
  147.  
  148.    if ((statusField==nil)
  149.        ||(mailbox==nil)||((size=[mailbox storeSize])<0)) return;
  150.  
  151.    val=[statusField stringValue];
  152.  
  153.    if (strstr(val,"MB"))
  154.       sprintf(buf,"%s \320 index (%.1fMB)",val,size/(1<<20));
  155.    else if (strstr(val,"KB"))
  156.       sprintf(buf,"%s \320 index (%.0fKB)",val,size/(1<<10));
  157.    else
  158.       sprintf(buf,"%s \320 index",val);
  159.    
  160.    [statusField setStringValue:buf];
  161.    }
  162.  
  163. - drawSelf:(const NXRect *)rects :(int)rectCount
  164.    {
  165.    id ret=[super drawSelf:rects:rectCount];
  166.    NXPoint p;
  167.    NXSize s;
  168.    if ((mailbox==nil)||(indextag_image==nil)) return nil;
  169.    
  170.    [indextag_image getSize:&s];
  171.    p.x=0; p.y=s.height;
  172.    if ([mailbox hasStore]) [indextag_image composite:NX_SOVER toPoint:&p];
  173.    return ret;
  174.    }
  175. @end
  176.  
  177. @implementation CommandView(EnhanceMailReader)
  178. - setXFace:(const char *)xface
  179.    {
  180.    NXSize size;
  181.    
  182.    if (face) return self;
  183.    size.width=size.height=64;
  184.    face=[[NXImage alloc] initXFace:xface size:&size];
  185.    [self display];
  186.    return self;
  187.    }
  188.  
  189. - setXImageURL:(const char *)ximageurl
  190.    {
  191.    if (face) return self;
  192.    face=[[NXImage alloc] initURL:ximageurl];
  193.    [self display];
  194.    return self;
  195.    }
  196. @end
  197.